/*     */ package com.zimbra.cs.service.admin;
/*     */ 
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.AdminConstants;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.util.SetUtil;
/*     */ import com.zimbra.cs.account.accesscontrol.AdminRight;
/*     */ import com.zimbra.cs.account.accesscontrol.AttrRight;
/*     */ import com.zimbra.cs.account.accesscontrol.RightManager;
/*     */ import com.zimbra.cs.account.accesscontrol.Rights.Admin;
/*     */ import com.zimbra.cs.account.accesscontrol.TargetType;
/*     */ import com.zimbra.cs.ldap.LdapTODO.ACLTODO;
/*     */ import com.zimbra.soap.DocumentDispatcher;
/*     */ import com.zimbra.soap.DocumentHandler;
/*     */ import com.zimbra.soap.SoapEngine;
/*     */ import com.zimbra.soap.ZimbraSoapContext;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashSet;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ import java.util.TreeMap;
/*     */ import java.util.TreeSet;
/*     */ import org.dom4j.QName;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class GetRightsDoc
/*     */   extends AdminDocumentHandler
/*     */ {
/*     */   public Element handle(Element request, Map<String, Object> context)
/*     */     throws ServiceException
/*     */   {
/*  49 */     ZimbraSoapContext lc = getZimbraSoapContext(context);
/*     */     
/*  51 */     HashSet<String> specificPackages = null;
/*  52 */     for (Element ePackage : request.listElements("package")) {
/*  53 */       if (specificPackages == null)
/*  54 */         specificPackages = new HashSet();
/*  55 */       specificPackages.add(ePackage.getAttribute("name"));
/*     */     }
/*     */     
/*  58 */     Element response = lc.createElement(AdminConstants.GET_RIGHTS_DOC_RESPONSE);
/*  59 */     doGetRightsDoc(context, specificPackages, response);
/*  60 */     return response;
/*     */   }
/*     */   
/*     */   private void doGetRightsDoc(Map<String, Object> context, HashSet<String> specificPackages, Element response) throws ServiceException
/*     */   {
/*  65 */     SoapEngine engine = (SoapEngine)context.get("zimbra.engine");
/*  66 */     DocumentDispatcher dispatcher = engine.getDocumentDispatcher();
/*     */     
/*  68 */     Map<QName, DocumentHandler> handlers = dispatcher.getHandlers();
/*     */     
/*     */ 
/*  71 */     Map<String, TreeMap<String, AdminRightCheckPoint>> handlersWithRightsDoc = new TreeMap();
/*     */     
/*  73 */     for (Map.Entry<QName, DocumentHandler> handler : handlers.entrySet())
/*     */     {
/*  75 */       DocumentHandler soapHandler = (DocumentHandler)handler.getValue();
/*     */       
/*  77 */       if ((soapHandler instanceof AdminRightCheckPoint)) {
/*  78 */         QName qname = (QName)handler.getKey();
/*  79 */         String pkg = soapHandler.getClass().getPackage().getName();
/*     */         
/*  81 */         if ((specificPackages == null) || (specificPackages.contains(pkg)))
/*     */         {
/*     */ 
/*  84 */           TreeMap<String, AdminRightCheckPoint> handlersInPkg = (TreeMap)handlersWithRightsDoc.get(pkg);
/*  85 */           if (handlersInPkg == null) {
/*  86 */             handlersInPkg = new TreeMap();
/*  87 */             handlersWithRightsDoc.put(pkg, handlersInPkg);
/*     */           }
/*     */           
/*  90 */           handlersInPkg.put(qname.getQualifiedName(), (AdminRightCheckPoint)soapHandler);
/*     */         }
/*     */       }
/*     */     }
/*  94 */     Set<AdminRight> usedRights = new HashSet();
/*     */     
/*  96 */     List<AdminRight> relatedRights = new ArrayList();
/*  97 */     List<String> notes = new ArrayList();
/*  98 */     for (Map.Entry<String, TreeMap<String, AdminRightCheckPoint>> entry : handlersWithRightsDoc.entrySet()) {
/*  99 */       String pkg = (String)entry.getKey();
/* 100 */       Map<String, AdminRightCheckPoint> handlersInPkg = (Map)entry.getValue();
/*     */       
/* 102 */       ePackage = response.addElement("package");
/* 103 */       ePackage.addAttribute("name", pkg);
/*     */       
/* 105 */       for (Map.Entry<String, AdminRightCheckPoint> handler : handlersInPkg.entrySet()) {
/* 106 */         String soapName = (String)handler.getKey();
/* 107 */         AdminRightCheckPoint soapHandler = (AdminRightCheckPoint)handler.getValue();
/*     */         
/* 109 */         relatedRights.clear();
/* 110 */         notes.clear();
/* 111 */         soapHandler.docRights(relatedRights, notes);
/*     */         
/* 113 */         Element eCommand = ePackage.addElement("cmd");
/* 114 */         eCommand.addAttribute("name", soapName);
/* 115 */         Element eRights = eCommand.addElement("rights");
/*     */         
/* 117 */         for (AdminRight adminRight : relatedRights) {
/* 118 */           Element eRight = eRights.addElement("right");
/* 119 */           eRight.addAttribute("name", adminRight.getName());
/*     */           
/* 121 */           usedRights.add(adminRight);
/*     */         }
/*     */         
/* 124 */         eNotes = eCommand.addElement("desc");
/* 125 */         for (String note : notes)
/* 126 */           eNotes.addElement("note").setText(note); } }
/*     */     Element ePackage;
/*     */     Element eNotes;
/* 129 */     genNotUsed(usedRights, response);
/* 130 */     genDomainAdminRights(context, response);
/*     */   }
/*     */   
/*     */   private void genNotUsed(Set<AdminRight> usedRights, Element response) throws ServiceException {
/* 134 */     Set<AdminRight> allRights = new HashSet();
/* 135 */     allRights.addAll(RightManager.getInstance().getAllAdminRights().values());
/* 136 */     Set<AdminRight> notUsed = SetUtil.subtract(allRights, usedRights);
/* 137 */     for (AdminRight nu : notUsed)
/* 138 */       response.addElement("notUsed").setText(nu.getName());
/*     */   }
/*     */   
/*     */   @LdapTODO.ACLTODO
/*     */   private void genDomainAdminRights(Map<String, Object> context, Element response) throws ServiceException {
/* 143 */     Element eDomainAdmin = response.addElement("domainAdmin-copypaste-to-zimbra-rights-domainadmin-xml-template");
/*     */     
/* 145 */     SoapEngine engine = (SoapEngine)context.get("zimbra.engine");
/* 146 */     DocumentDispatcher dispatcher = engine.getDocumentDispatcher();
/*     */     
/* 148 */     Map<QName, DocumentHandler> handlers = dispatcher.getHandlers();
/*     */     
/*     */ 
/*     */ 
/* 152 */     Map<TargetType, TreeSet<String>> rights = new TreeMap();
/* 153 */     for (TargetType tt : TargetType.values()) {
/* 154 */       rights.put(tt, new TreeSet());
/*     */     }
/*     */     
/* 157 */     ((TreeSet)rights.get(TargetType.account)).add(Rights.Admin.R_setDomainAdminAccountAndCalendarResourceAttrs.getName());
/* 158 */     ((TreeSet)rights.get(TargetType.calresource)).add(Rights.Admin.R_setDomainAdminAccountAndCalendarResourceAttrs.getName());
/* 159 */     ((TreeSet)rights.get(TargetType.calresource)).add(Rights.Admin.R_setDomainAdminCalendarResourceAttrs.getName());
/* 160 */     ((TreeSet)rights.get(TargetType.dl)).add(Rights.Admin.R_setDomainAdminDistributionListAttrs.getName());
/* 161 */     ((TreeSet)rights.get(TargetType.domain)).add(Rights.Admin.R_setDomainAdminDomainAttrs.getName());
/*     */     
/* 163 */     for (Map.Entry<QName, DocumentHandler> handler : handlers.entrySet()) {
/* 164 */       DocumentHandler soapHandler = (DocumentHandler)handler.getValue();
/*     */       
/*     */ 
/* 167 */       if (((soapHandler instanceof AdminRightCheckPoint)) && ((soapHandler instanceof AdminDocumentHandler)))
/*     */       {
/* 169 */         AdminDocumentHandler adminHandler = (AdminDocumentHandler)soapHandler;
/* 170 */         if (adminHandler.domainAuthSufficient(context)) {
/* 171 */           List<AdminRight> relatedRights = new ArrayList();
/* 172 */           List<String> notes = new ArrayList();
/* 173 */           adminHandler.docRights(relatedRights, notes);
/*     */           
/* 175 */           for (i$ = relatedRights.iterator(); i$.hasNext();) { r = (AdminRight)i$.next();
/* 176 */             if (r.isPresetRight()) {
/* 177 */               TargetType tt = r.getTargetType();
/* 178 */               ((TreeSet)rights.get(tt)).add(r.getName());
/* 179 */             } else if (r.isAttrRight()) {
/* 180 */               Set<TargetType> tts = ((AttrRight)r).getTargetTypes();
/* 181 */               for (TargetType tt : tts)
/* 182 */                 ((TreeSet)rights.get(tt)).add(r.getName());
/*     */             }
/*     */           }
/*     */         }
/*     */       } }
/*     */     Iterator i$;
/*     */     AdminRight r;
/* 189 */     for (Map.Entry<TargetType, TreeSet<String>> entry : rights.entrySet()) {
/* 190 */       TargetType tt = (TargetType)entry.getKey();
/*     */       
/* 192 */       if (((TreeSet)entry.getValue()).size() > 0) {
/* 193 */         Element eRight = eDomainAdmin.addElement("right").addAttribute("name", "domainAdmin" + tt.getPrettyName() + "Rights").addAttribute("type", "combo");
/* 194 */         eRight.addElement("desc").setText("domain admin " + tt.getCode() + " right");
/* 195 */         eRights = eRight.addElement("rights");
/* 196 */         for (String r : (TreeSet)entry.getValue())
/* 197 */           eRights.addElement("r").addAttribute("n", r);
/*     */       }
/*     */     }
/*     */     Element eRights;
/*     */   }
/*     */   
/*     */   public boolean needsAuth(Map<String, Object> context) {
/* 204 */     return false;
/*     */   }
/*     */   
/*     */   public boolean needsAdminAuth(Map<String, Object> context) {
/* 208 */     return false;
/*     */   }
/*     */   
/*     */   public void docRights(List<AdminRight> relatedRights, List<String> notes)
/*     */   {
/* 213 */     notes.add("Do not need any right, all admins are allowed.");
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/service/admin/GetRightsDoc.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */